---@class MoveBackAction:AbstractLeaf
local MoveBackAction = ClientFight.CreateClass("MoveBackAction", ClientFight.AbstractLeaf, ClientFight.IAction)
---@return EStatus
function MoveBackAction:update()
    local moving = self.fighter.moveBack
    ---@type Vector2
    local position = nil
    if (self.fighter.position.x + self.fighter.shape.length / 2.0 > Global.FIGHT_INNER_ROUND[2][1]) then
        self.fighter.moveBack = true
        self.fighter.moveDirection = Global.LEFT
        local bd = Global.FIGHT_INNER_ROUND[2][1]
        local subBd = self.fighter.shape.length / 2.0
        position = Vector2.New(bd - subBd, self.fighter.position.y)
    elseif self.fighter.position.x - self.fighter.shape.length / 2.0 < Global.FIGHT_INNER_ROUND[1][1] then
        local bd = Global.FIGHT_INNER_ROUND[1][1]
        local addBd = self.fighter.shape.length / 2.0
        self.fighter.moveBack = true
        self.fighter.moveDirection = Global.RIGHT
        position = Vector2.New(bd + addBd, self.fighter.position.y)
    else
        self.fighter.moveBack = false
        self.fighter.moveDirection = 0
        if moving then
            ReportManager.setMoveEndToJsonString(self.fight, self.fighter, self.fighter.moveAction)
            self.fighter.moveAction = nil
        end
        SkillRoleMgr.savePathFile("[" .. self.fight.frame .. "][STOP]Fighter " .. self.fighter.fighterId .. " 停止移动"
                .. self.fighter.position);
        return EStatus.SUCCESS;
    end
    if not moving then
        self.fighter.moveAction = ReportManager.moveToJsonString(self.fight, self.fighter)
        table.insert(self.fight.actions, clone(self.fighter.moveAction))
        FightManager.playActions(self.fighter.moveAction)

    end
    -- 开始移动
    local distance = math.abs(self.fighter.position.x - position.x)
    local logPosition = position
    SkillRoleMgr.savePathFile("[" .. self.fight.frame .. "][边界移动]" .. self.fighter .. "准备移动：当前坐标" .. self.fighter.position .. "，目标坐标：" .. logPosition);
    local speed = 0;
    speed = FighterManager.getFighterMoveSpeed(self.fighter)
    local moved = speed * Global.FIGHT_FRAME / 1000
    local logSpeed = speed
    if distance <= moved then
        FighterManager.changePosition(self.fight, self.fighter, 0, position.x, self.fighter.position.y, 0, false, true);
        SkillRoleMgr.savePathFile("[" .. self.fight.frame .. "][边界移动]" .. self.fighter .. "进行速度(" .. logSpeed .. ")移动：移动到" .. self.fighter.position);

        SkillRoleMgr.savePathFile("[" .. self.fight.frame .. "][MOVE]Fighter " .. self.fighter.fighterId .. " 移动到"
                .. self.fighter.position);
        return EStatus.SUCCESS;
    end
    FighterManager.changePosition(self.fight, self.fighter, 0, self.fighter.position.x + self.fighter.moveDirection * moved, self.fighter.position.y, 0, false, true)
    SkillRoleMgr.savePathFile("[" .. self.fight.frame .. "][边界移动]" .. self.fighter .. "进行速度(" .. logSpeed .. ")移动：移动到" .. self.fighter.position);
    SkillRoleMgr.savePathFile("[" .. self.fight.frame .. "][MOVE]Fighter " .. self.fighter.fighterId .. " 移动到" .. self.fighter.position);
    ReportManager.setMoveEndToJsonString(self.fight, self.fighter, self.fighter.moveAction)
    table.insert(self.fight.actions, clone(self.fighter.moveAction))
    FightManager.playActions(self.fighter.moveAction);

    return EStatus.SUCCESS
end